// 导入静态路由和动态路由
import { asyncRouter, constantRoutes } from '@/router'

const state = {
    routes: constantRoutes
}

const mutations = {
    setRoutes(state, newRoutes) {
        state.routes=[...constantRoutes,...newRoutes]
    }
}

const actions = {
    getAsyncRoutes(context, menus) {
        let routes = asyncRouter.filter(item => menus.includes(item.name))
        routes.push({ path: '*', redirect: '/404', hidden: true })
        context.commit('setRoutes', routes)
        return routes
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}